/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.Simulator;

import br.ufg.inf.si.poo.formula1.GUI.FrameMain;
import br.ufg.inf.si.poo.formula1.ManagementFiles.ManagementFiles;
import br.ufg.inf.si.poo.formula1.Season.Season;

/**
 * SimulatorSeason
 * 
 * Versao 1.0
 * 
 * Data 28/01/2013
 * 
 * @author Igor
 */
public class SimulatorSeason {
    //Construtores
    private SimulatorSeason(){}
    
    /**
     * Realiza a leitura, dos arquivos pre-definidos com dados reais retirados
     * do site Formula1.com, para dentro dos vetores de Equipe, Piloto e Cricuito
     * @param season 
     */
    public static void readAllFiles(Season season){
        /* Leitura de equipes */
        ManagementFiles.readTeam(FrameMain.getTeams());
        //ManagementFiles.readTeam(season);
        
        /* Leitura de pilotos */
        ManagementFiles.readDriver(FrameMain.getDrivers());
        //ManagementFiles.readDriver(season);
        
        /* Leitura de circuitos */
        ManagementFiles.readCircuit(FrameMain.getCircuits());
        //ManagementFiles.readCircuit(season);
        
        /* Contrata os pilotos do arquivo INICIAL */
        //ManagementFiles.readHireDriverDefault();
        //ManagementFiles.readHireDriverDefault(season);
    }

    /**
     * Executa a simulacao de tds corridas existentes
     * @param season 
     */
    private static void executeRaces(Season season){
        for(int i = 0;i < season.getQttCircuits();i++){
            SimulatorRace.executeRace(season, season.getRace()[i]);
        }
    }
    
    /**
     * Apos a temporada e gerado o vetor de campeao mundial e campeao mundial de contrutor
     * @param season 
     */
    private static void afterSeason(Season season){
        /* Campeao mundial */
        season.worldChampion();

        /* Campeonato mundial de contrutores */
        season.worldChampionshipBuilders();
    }
    
    /**
     * Executa as funcoes da simulacao da temporada
     * @param season 
     */
    public static void executeSeason(Season season){
        SimulatorSeason.readAllFiles(season);
        SimulatorSeason.executeRaces(season);
        SimulatorSeason.afterSeason(season);

    }
}